Conditions | 6 |
Total Lines | 57 |
Code Lines | 46 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | import React from "react"; |
||
6 | |||
7 | |||
8 | |||
9 | export default function NavBar({navigation, mapRef, position}) { |
||
10 | const [howModal, setHowModal] = useState(false); |
||
11 | |||
12 | function DrawerButton({navigation}) { |
||
13 | return ( |
||
14 | <Pressable style={[styles.drawer, styles.shadowProp]} onPress={() => navigation.openDrawer()}> |
||
15 | <Icon |
||
16 | name='three-bars' |
||
17 | size={20} |
||
18 | color='black' |
||
19 | /> |
||
20 | </Pressable> |
||
21 | ); |
||
22 | }; |
||
23 | |||
24 | function HowToDrive({navigation}) { |
||
25 | return ( |
||
26 | <Pressable style={[styles.info, styles.shadowProp]} onPress={() => setHowModal(!howModal)}> |
||
27 | <Icon |
||
28 | name='question' |
||
29 | size={16} |
||
30 | color='black' |
||
31 | /> |
||
32 | <Text style={{marginLeft: 8}}>How to drive?</Text> |
||
33 | </Pressable> |
||
34 | ) |
||
35 | } |
||
36 | |||
37 | function Location({navigation}) { |
||
38 | return ( |
||
39 | <Pressable style={[styles.drawer, styles.shadowProp]} onPress={() => { |
||
40 | mapRef.current.animateToRegion({ |
||
41 | latitude: position.latitude? position.latitude : 56.161013580817986, |
||
42 | longitude: position.longitude? position.longitude : 15.587742977884904, |
||
43 | latitudeDelta: 0.03, |
||
44 | longitudeDelta: 0.03, |
||
45 | }) |
||
46 | }}> |
||
47 | <Icon |
||
48 | name='location' |
||
49 | size={20} |
||
50 | color='black' |
||
51 | /> |
||
52 | </Pressable> |
||
53 | ); |
||
54 | } |
||
55 | |||
56 | return ( |
||
57 | <View style={styles.container}> |
||
58 | <DrawerButton navigation={navigation}/> |
||
59 | <HowToDrive navigation={navigation}/> |
||
60 | <Location navigation={navigation}/> |
||
61 | <HowModal navigation={navigation} modalVisible={howModal} setModalVisible={setHowModal}></HowModal> |
||
62 | </View> |
||
63 | ) |
||
98 | }); |